home *** CD-ROM | disk | FTP | other *** search
/ Kids' Bible Fun Pack / Kids' CD-ROM Bible Fun Pack (1997)(Education Publishing Concepts)[Mac-PC].iso / mac / BIBLEC / XTRAS / Animation Wizard / 00013_Script_ScoreMgr < prev    next >
Text File  |  1996-07-17  |  17KB  |  485 lines

  1. -- ScoreMgr script
  2.  
  3. property iUsersScoreSelection
  4. property iGeneratedScoreSelection
  5. property ichStart
  6. property ichEnd
  7. property iFrameStart
  8. property iFrameEnd
  9. property iStageWidth
  10. property iStageHeight
  11. property iStageRight
  12. property iStageBottom
  13. property iChannelAvailList
  14. property ichReselect
  15. property iLocReselect
  16.  
  17. property ikChStart
  18. property ikChEnd
  19. property ikFrameStart
  20. property ikFrameEnd
  21.  
  22. property iLastFrame
  23. property iNeedClean
  24.  
  25. on birth me
  26.   tell the stage
  27.     set iStageRight = the StageRight
  28.     set iStageBottom = the StageBottom
  29.     set iStageWidth = iStageRight - the StageLeft
  30.     set iStageHeight = iStageBottom - the StageTop
  31.   end tell
  32.   set ikChStart = 1
  33.   set ikChEnd = 2
  34.   set ikFrameStart = 3
  35.   set ikFrameEnd = 4
  36.   set iChannelAvailList = []
  37.   set iGeneratedScoreSelection = []
  38.   set ichReselect = 18
  39.   
  40.   return me
  41. end birth
  42.  
  43. on mGetStageWidth me
  44.   return iStageWidth
  45. end mGetStageWidth
  46.  
  47. on mGetStageHeight me
  48.   return iStageHeight
  49. end mGetStageHeight
  50.  
  51. on mGetStageRight me
  52.   return iStageRight
  53. end mGetStageRight
  54.  
  55. on mGetStageBottom me
  56.   return iStageBottom
  57. end mGetStageBottom
  58.  
  59. on mInit me, nFramesNeeded, nChannelsNeeded
  60.   global gDevelopmentFlag 
  61.   
  62.   if nFramesNeeded > 32000 then
  63.     alert("The combination of text and settings you have chosen would generate an " & ¼
  64.     "animation of more than 32000 frames.  Please simplify your selections and try again.")
  65.     return FALSE
  66.   end if
  67.   
  68.   tell the stage   
  69.     set iUsersScoreSelection = the scoreSelection
  70.     set iLastFrame = the lastFrame
  71.     set iStageRight = the StageRight   --check the stage location again, in case it has changed.
  72.     set iStageBottom = the StageBottom
  73.     set iStageWidth = iStageRight - the StageLeft
  74.     set iStageHeight = iStageBottom - the StageTop
  75.   end tell
  76.   if iUsersScoreSelection = [] then
  77.     alert("Please select a range of cells or frames in the score and try again.")
  78.     return FALSE
  79.   end if
  80.   
  81.   if gDevelopmentFlag then -- for development only
  82.     mForceSelection(me)    
  83.   end if
  84.   set iLocReselect = the loc of sprite ichReselect -- save for later
  85.   puppetSprite ichReselect, TRUE
  86.   
  87.   -- We must parse the user's selection and do the appropriate thing.
  88.   
  89.   set firstScoreSelectionList = getAt(iUsersScoreSelection, 1)
  90.   set ichStart = getAt(firstScoreSelectionList, ikChStart)
  91.   set ichEnd = getAt(firstScoreSelectionList, ikChEnd)
  92.   set iFrameStart = getAt(firstScoreSelectionList, ikFrameStart)
  93.   set iFrameEnd = getAt(firstScoreSelectionList, ikFrameEnd)
  94.   set theGeneratedFrameEnd = iFrameStart + nFramesNeeded - 1
  95.   
  96.   --check to see if the ending frame is the last frame and put in a tempo setting if it is.
  97.   set theEnd to max(theGeneratedFrameEnd, iFrameEnd)
  98.   if theEnd >= iLastFrame then
  99.     set iNeedClean = true
  100.     tell the stage
  101.       beginRecording
  102.         go to frame (theEnd + 5)
  103.         set the frameTempo to 5
  104.       endrecording
  105.     end tell
  106.   else 
  107.     set iNeedClean = false
  108.   end if
  109.   
  110.   set iChannelAvailList = []
  111.   if (ichStart = -5) and (ichEnd = 48) then -- user selected a whole frame
  112.     -- Make a list saying all 48 channels are available
  113.     repeat with ch = 1 to 48
  114.       add iChannelAvailList, ch
  115.     end repeat
  116.     
  117.     tell the stage
  118.       beginRecording
  119.         
  120.         -- If the user selected a range of full frames, delete these frames.
  121.         -- This will simulate an insertion cursor
  122.         if iFrameEnd >= iFrameStart then 
  123.           --      tell the stage
  124.           go to frame iFrameStart
  125.           --        beginRecording
  126.           repeat with theFrameNum = iFrameStart to iFrameEnd
  127.             -- The following line deletes any frame marker
  128.             set the frameLabel = 0
  129.             deleteFrame
  130.           end repeat 
  131.           --        endRecording
  132.           --      end tell
  133.         end if
  134.         
  135.         -- Now we basically have an insertion cursor in the score
  136.         -- So, here we insert frames
  137.         tell the stage
  138.           if iFrameStart = 1 then
  139.             go to frame 1
  140.           else
  141.             go to frame iFrameStart - 1
  142.           end if
  143.           
  144.           --          beginRecording
  145.           repeat with i = 1 to nFramesNeeded
  146.             insertFrame
  147.           end repeat
  148.           --          endRecording
  149.           
  150.           if iFrameStart = 1 then
  151.             go to frame 1
  152.           else
  153.             go to frame iFrameStart - 1
  154.           end if
  155.         end tell
  156.         
  157.         --check again, in case the ending frame got deleted while deleting & inserting frames.
  158.         set theEnd to max(theGeneratedFrameEnd, iFrameEnd)
  159.         if theEnd >= iLastFrame then
  160.           set iNeedClean = true
  161.           --          tell the stage
  162.           --            beginRecording
  163.           go to frame (theEnd + 5)
  164.           set the frameTempo to 5
  165.           --            endrecording
  166.           --          end tell
  167.         else 
  168.           set iNeedClean = false
  169.         end if
  170.         
  171.       endRecording
  172.     end tell
  173.     set iGeneratedScoreSelection = [[-5, 48, iFrameStart, theGeneratedFrameEnd]]
  174.     
  175.     -- Otherwise, the user has selected  one or more channels  
  176.   else    
  177.     --  Build a list of channels that the user has selected.    
  178.     set iGeneratedScoreSelection  = []
  179.     set nItems = count(iUsersScoreSelection)
  180.     repeat with thisSelection = 1 to nItems
  181.       set thisScoreSelectionList = getAt(iUsersScoreSelection, thisSelection)
  182.       set thisChStart = getAt(thisScoreSelectionList, ikChStart)
  183.       if thisChStart <= 0 then
  184.         alert("Please make your score selection in channels 1 through 48")
  185.         mClean me
  186.         return FALSE
  187.       end if
  188.       set thisChEnd = getAt(thisScoreSelectionList, ikChEnd)
  189.       -- add this to the Generated score selection
  190.       set thisScoreSelection = [thisChStart, thisChEnd, iFrameStart, theGeneratedFrameEnd]
  191.       addAt(iGeneratedScoreSelection, thisScoreSelection)
  192.       
  193.       -- add each of the user's selected channels to the channel available list
  194.       repeat with thisCh = thisChStart to thisChEnd
  195.         add(iChannelAvailList, thisCh)
  196.       end repeat
  197.       
  198.     end repeat
  199.     set nChannelsAvail = count(iChannelAvailList)
  200.     if nChannelsNeeded > nChannelsAvail then
  201.       alert("Your animation requires" && nChannelsNeeded && "channels, " & ¼
  202.                 "but you have only selected" && nChannelsAvail && "channels.  " & ¼
  203.                  "Please select more and try again.")
  204.       mClean me
  205.       return FALSE
  206.     end if
  207.     
  208.     -- If we don't have enough frames in the selection,
  209.     -- duplicate the last frame until we have enough
  210.     --but make sure we don't duplicate the tempo channel
  211.     set nFramesSelected = iFrameEnd - iFrameStart + 1   
  212.     
  213.     if nFramesSelected < nFramesNeeded then
  214.       set nFramesToAdd = nFramesNeeded - nFramesSelected
  215.       tell the stage
  216.         go to frame iFrameEnd
  217.         beginRecording
  218.           
  219.           repeat with i = 1 to nFramesToAdd
  220.             duplicateFrame
  221.             set the frameTempo = 0
  222.           end repeat
  223.         endRecording
  224.         go to frame iFrameStart
  225.       end tell    
  226.     end if  --nFramesSelected
  227.   end if
  228.   
  229.   
  230.   -- Finally, clear out all user selected cells in the generated score
  231.   --  and clear out the tempo channel, in case of reselection
  232.   
  233.   tell the stage
  234.     beginRecording
  235.       go to frame iFrameStart
  236.       repeat with thisFrame = iFrameStart to iFrameEnd
  237.         repeat with chIndex = 1 to nChannelsAvail
  238.           set thisCh = getAt(iChannelAvailList, chIndex)
  239.           if the castNum of sprite thisCh <> 0 then
  240.             set the type of sprite thisCh = 0  --  delete anything that's there
  241.           end if
  242.         end repeat
  243.         set the frameTempo = 0
  244.         updateFrame
  245.       end repeat
  246.     endRecording
  247.   end tell
  248.   
  249.   
  250.   
  251.   --put "Channels that are available are :" && iChannelAvailList
  252.   --put "The Generated score selection is:" && iGeneratedScoreSelection
  253.   updateStage
  254.   
  255.   return TRUE  
  256. end mInit
  257.  
  258. on mShowReselect me
  259.   set the scoreSelection = iUsersScoreSelection
  260.   set the loc of sprite ichReselect = iLocReselect
  261.   set the castNum of sprite ichReselect = the number of cast "ReselectButton"
  262.   updateStage
  263. end mShowReselect
  264.  
  265.  
  266. on mForceSelection me  
  267.   -- This ensures that we don't overwrite stuff in the MIAW
  268.   -- when we are using it as a development movie (not a MIAW)
  269.   -- If I goofed and forgot to select a testing area of the score,
  270.   -- make believe I selected frames 101 to 125
  271.   
  272.   set nItems = count(iUsersScoreSelection)
  273.   repeat with thisSelectionNum = 1 to nItems
  274.     set thisScoreSelectionList = getAt(iUsersScoreSelection, thisSelectionNum)
  275.     set thisStart = getAt(thisScoreSelectionList, ikFrameStart)
  276.     set thisEnd = getAt(thisScoreSelectionList, ikFrameEnd)
  277.     
  278.     if (thisStart < 101) or (thisEnd < 101) then
  279.       setAt(thisScoreSelectionList, ikFrameStart, 101)
  280.       setAt(thisScoreSelectionList, ikFrameEnd, 125)
  281.       setAt(iUsersScoreSelection, thisSelectionNum, thisScoreSelectionList)
  282.     end if
  283.   end repeat
  284.   
  285. end mForceSelection
  286.  
  287. on mReselect me
  288.   if iGeneratedScoreSelection = [] then
  289.     alert("Internal error, mReselect - there is nothing to reselect.")
  290.     return
  291.   end if
  292.   tell the stage
  293.     set the scoreSelection = iGeneratedScoreSelection
  294.   end tell
  295. end mReselect
  296.  
  297. on mGetGeneratedScoreSelection me
  298.   return iGeneratedScoreSelection
  299. end mGetGeneratedScoreSelection
  300.  
  301.  
  302.  
  303. on mGetStartFrame me
  304.   return iFrameStart
  305. end mGetStartFrame
  306.  
  307. on mGetNextSelectedChannel me
  308.   -- Get the first in the list of users selected channels set up in mInit, 
  309.   -- return it, and eliminate it from the list of available channels
  310.   
  311.   if iChannelAvailList = [] then
  312.     alert("Internal error, mGetNextSelectedChannel is out of available channels")
  313.     return -99
  314.   end if
  315.   set theCh = getAt(iChannelAvailList, 1)
  316.   deleteAt(iChannelAvailList, 1)
  317.   
  318.   return theCh
  319. end mGetNextSelectedChannel
  320.  
  321.  
  322. on mWriteSprite me, f, ch, cm, theForeColor, theBackColor, x, y, w, h
  323.   global gkTransparentInk
  324.   
  325.   tell the stage
  326.     go frame ( f )
  327.     beginRecording 
  328.       -- sprite properties
  329.       set the castNum of sprite ch = cm
  330.       set the foreColor of sprite ch = theForeColor
  331.       set the backColor of sprite ch = theBackColor
  332.       set the locH  of sprite ch = x
  333.       set the locV  of sprite ch = y
  334.       set the ink of sprite ch = gkTransparentInk
  335.       
  336.       -- last two are primarily to support Zoom effect
  337.       if w <> 0 then 
  338.         set the width  of sprite ch = w
  339.       end if
  340.       if h <> 0 then 
  341.         set the height of sprite ch = h
  342.       end if
  343.       updateFrame
  344.       -- debug( "Writing Sprite:" && s && the type of sprite s && the castNum of sprite s && ¼
  345.              the foreColor of sprite s && the backColor of sprite s && ¼
  346.              the locH of sprite s && the locV of sprite s && ¼
  347.              the width of sprite s && the height of sprite s )
  348.     endRecording
  349.   end tell
  350. end mWriteScore
  351.  
  352. on mWriteFrameControl me, theFrame, theControl, theValue
  353.   if theControl = #Transition then -- copy a known transition
  354.     copyToClipBoard member (the number of member theValue)    
  355.     --  Create a cast member in the stage movie  
  356.     set castNumTransTarget = mFindFreeCastRun(goCastMgr, 1, 1)
  357.   end if
  358.   tell the stage
  359.     go frame theFrame
  360.     beginRecording 
  361.       case theControl of
  362.         #Label:  set the frameLabel = theValue
  363.         #Tempo: set the frameTempo = theValue
  364.         #Transition:   -- Copied transition to clipboard already (above)
  365.           pasteClipboardInto member castNumTransTarget
  366.           set the name of member castNumTransTarget  = "Transition" && string(the ticks)
  367.           set the frameTransition = castNumTransTarget
  368.         #Sound1:  set the frameSound1 = theValue
  369.         #Sound2:  set the frameSound2 = theValue
  370.         otherwise  alert("Bad control value passed to mWriteFrameControl" & theControl)
  371.       end case   
  372.       updateFrame
  373.     endRecording
  374.   end tell  
  375. end mWriteFrameControl
  376.  
  377.  
  378. on mWriteFrameLabel me, theFrame, theLabel
  379.   mWriteFrameControl(me, theFrame, #Label, theLabel)
  380. end mWriteFrameLabel
  381.  
  382. -- Writing a frame delay is painful. Unfortunately, there is no
  383. -- easy way to just set this property.  So, we have to write 1
  384. -- frame for each second delay, and set the frame tempo
  385. -- of that frame to 1 frame per second.
  386. --on mWriteFrameDelay me, theFrame, nSeconds
  387. --  if nSeconds > 0 then
  388. --    repeat with thisFrame = 1 to nSeconds
  389. --      mWriteFrameControl(me, (theFrame + thisFrame - 1), #Tempo, 1)
  390. --    end repeat    
  391. --  end if  
  392. --end mWriteFrameDelay
  393.  
  394. --undocumented lingo: setting the frameTempo to a negative number sets it to wait for that many seconds.
  395. on mWriteFrameDelay me, theFrame, nSeconds
  396.   mWriteFrameControl(me,theFrame, #Tempo, -nSeconds )
  397. end mWriteFrameDelay
  398.  
  399. on mWriteFrameTempo me, theFrame, theTempo
  400.   mWriteFrameControl(me, theFrame, #Tempo, theTempo)
  401. end mWriteFrameTempo
  402.  
  403. on mWriteFrameTransition me, theFrame, theTransition
  404.   mWriteFrameControl(me, theFrame, #Transition, theTransition)
  405. end mWriteFrameTransition
  406.  
  407. on mWriteFrameSound1 me, theFrame, theSound1
  408.   mWriteFrameControl(me, theFrame, #Sound1, theSound1)
  409. end mWriteFrameSound1
  410.  
  411. on mWriteFrameSound2 me, theFrame, theSound2
  412.   mWriteFrameControl(me, theFrame, #Sound2, theSound2)
  413. end mWriteSound2
  414.  
  415.  
  416. -- pass in a list of all the frames to be recorded in and what to be recorded in each.
  417. on mWriteFrame me, frameList
  418.   global gkTransparentInk
  419.   tell the stage
  420.     beginRecording 
  421.       repeat with theFrameNum = 1 to count(frameList)
  422.         set theFrameStuff = getAt(frameList, theFrameNum)
  423.         --        put theFrameStuff
  424.         go to frame getAt(theFrameStuff, 1)
  425.         -- frame properties
  426.         repeat with theChannel = 2 to count(theFrameStuff)
  427.           set theChannelList = getAt(theFrameStuff, theChannel)
  428.           set theChannelType = getAt(theChannelList, 1)
  429.           case theChannelType of 
  430.             #label : set the frameLabel = getAt(theChannelList, 2)
  431.             #tempo : set the frameTempo = getAt(theChannelList, 2)
  432.             #palette : set the framePalette = getAt(theChannelList, 2)
  433.             #transition :  
  434.               set theTransition = getAt(theChannelList, 2)
  435.               set transitionMember = new(#transition)
  436.               if theTransition = "wipe down" then
  437.                 set the transitiontype of  transitionMember = 3
  438.                 set the chunkSize of transitionMember = 2
  439.               else if theTransition = "dissolve, pixels fast" then
  440.                 set the transitiontype of  transitionMember = 23
  441.                 set the chunkSize of transitionMember = 1
  442.               end if
  443.               set the duration of transitionMember = 2000
  444.               set the frameTransition = transitionMember
  445.             #sound1 :  set the frameSound1 = getAt(theChannelList, 2)
  446.             #sound2 :  set the frameSound2 = getAt(theChannelList, 2)
  447.             #sprite : 
  448.               set theSpriteNum = getAt(theChannelList, 2)
  449.               set the castNum of sprite theSpriteNum = getAt(theChannelList, 3)
  450.               set the foreColor of sprite theSpriteNum = getAt(theChannelList, 4)
  451.               set the backColor of sprite theSpriteNum = getAt(theChannelList, 5)
  452.               set the locH  of sprite theSpriteNum =getAt(theChannelList, 6)
  453.               set the locV  of sprite theSpriteNum = getAt(theChannelList, 7)
  454.               set the ink of sprite theSpriteNum = gkTransparentInk
  455.               set w = getAt(theChannelList, 8)
  456.               set h = getAt(theChannelList, 9)
  457.               -- last two are primarily to support Zoom effect
  458.               if w <> 0 then 
  459.                 set the width  of sprite theSpriteNum = w
  460.               end if
  461.               if h <> 0 then 
  462.                 set the height of sprite theSpriteNum = h
  463.               end if
  464.           end case
  465.           
  466.         end repeat  -- theChannel
  467.         updateFrame
  468.       end repeat  -- theFrameNum
  469.     endRecording
  470.   end tell
  471. end mWriteFrame
  472.  
  473. --gets rid of the extra tempo setting, if we set it. 
  474. on mClean me
  475.   if iNeedClean = true then
  476.     tell the stage
  477.       set iLastFrame = the lastFrame
  478.       beginRecording
  479.         go to frame iLastFrame
  480.         set the frameTempo to  0
  481.       endrecording
  482.     end tell
  483.   end if
  484. end mClean
  485.